//
//  PpOutDoorNotesViewController.swift
//  Palmpilot
//
//  Created by 杨伟毅 on 2018/10/30.
//  Copyright © 2018年 杨伟毅. All rights reserved.
//

import UIKit


class PpOutDoorNotesViewController: PpBaseViewController,UITableViewDataSource,UITableViewDelegate,DZNEmptyDataSetDelegate,DZNEmptyDataSetSource  {
    
    
    let baseView = UITableView.init(frame: ZCGRECT(x: 0, y: 0, width: SCREEN_width, height: SCREEN_HEIGHT-TopHeight))
    var titleArr = [PpBaseModel]()
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        self.title = PpLanguageSwitchTool.getString(key: "Outdoor notes")
        // 编辑页面内容
        let  rightBar = UIBarButtonItem.init(barButtonSystemItem: UIBarButtonSystemItem.add, target: self, action: #selector(editVC))
        self.navigationItem.rightBarButtonItem = rightBar
        titleArr = PpFmdbTools.shared.readVedioIdReturn(dateStr: "Ppname")
        if titleArr.count > 0  {
            baseView.reloadData()
        }
    }
    
   @objc  func editVC() -> Void {
          self.navigationController?.pushViewController(PpEditViewController(), animated: true)
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        baseView.delegate = self
        baseView.dataSource = self
        baseView.register(UINib(nibName: "PpSqlaseTableViewCell", bundle: Bundle.main),forCellReuseIdentifier: "PpSqlaseTableViewCell")
        baseView.estimatedRowHeight = 120
        baseView.tableFooterView = UIView()
        baseView.emptyDataSetSource = self
        baseView.emptyDataSetDelegate = self
        self.view .addSubview(baseView)
        PpBaseTool.insetTableViewAndUIViewController(baseView: baseView, baseVC: self)
//      titleArr = PpFmdbTools.shared.readVedioIdReturn(dateStr: "Ppname")
    }
    func numberOfSections(in tableView: UITableView) -> Int {
        return 1
    }
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        return titleArr.count
    }
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        let basecell:PpSqlaseTableViewCell? = tableView.dequeueReusableCell(withIdentifier: "PpSqlaseTableViewCell") as? PpSqlaseTableViewCell
        basecell?.showModelData(model: titleArr[indexPath.row])
        basecell?.selectionStyle = .none
        return basecell!
    }
    func tableView(_ tableView: UITableView, canEditRowAt indexPath: IndexPath) -> Bool {
        return true
    }
    func tableView(_ tableView: UITableView, editingStyleForRowAt indexPath: IndexPath) -> UITableViewCellEditingStyle {
        return UITableViewCellEditingStyle.delete
    }
    func tableView(_ tableView: UITableView, commit editingStyle: UITableViewCellEditingStyle, forRowAt indexPath: IndexPath) {
        PpFmdbTools.shared.delegateModel(model: titleArr[indexPath.row])
        titleArr = PpFmdbTools.shared.readVedioIdReturn(dateStr: "Ppname")
        baseView.reloadData()
    }
    //缺省图协议方法
    func image(forEmptyDataSet scrollView: UIScrollView!) -> UIImage! {
        return  UIImage(named: "error")
    }
    func emptyDataSetShouldDisplay(_ scrollView: UIScrollView!) -> Bool {
        return true
    }
    func description(forEmptyDataSet scrollView: UIScrollView!) -> NSAttributedString! {
        let textStr =  PpLanguageSwitchTool.getString(key: "You have not yet written an accompanying diary")
        let  paragraph = NSMutableParagraphStyle()
        paragraph.lineBreakMode = .byWordWrapping
        paragraph.alignment = .center
        let  attributes = [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 16.0),NSAttributedStringKey.foregroundColor: UIColor.lightGray, NSAttributedStringKey.paragraphStyle: paragraph]
        return NSAttributedString(string: textStr, attributes: attributes)
    }
//    func buttonTitle(forEmptyDataSet scrollView: UIScrollView!, for state: UIControlState) -> NSAttributedString! {
//        let textStr = "点我试试"
//        let  paragraph = NSMutableParagraphStyle()
//        paragraph.lineBreakMode = .byWordWrapping
//        paragraph.alignment = .center
//        let  attributes = [NSAttributedStringKey.font:UIFont.systemFont(ofSize: 15.0),NSAttributedStringKey.foregroundColor: UIColor.gray, NSAttributedStringKey.paragraphStyle: paragraph]
//        return NSAttributedString(string: textStr, attributes: attributes)
//    }
//    func emptyDataSet(_ scrollView: UIScrollView!, didTap button: UIButton!) {
//         titleArr = PpFmdbTools.shared.readVedioIdReturn(dateStr: "Ppname")
//         baseView.reloadData()
//    }
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
        let modeVC = PpEditViewController()
        modeVC.baseModel = titleArr[indexPath.row]
        self.navigationController?.pushViewController(modeVC, animated: true)
    }
    
    
    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    

    /*
    // MARK: - Navigation

    // In a storyboard-based application, you will often want to do a little preparation before navigation
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        // Get the new view controller using segue.destinationViewController.
        // Pass the selected object to the new view controller.
    }
    */

}
